package com.qf.util;

import com.qf.bean.Employee;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

/**
 * 2019/11/22
 * 键盘敲烂，月薪过万
 * 登高必自卑，行远必自迩。
 * 不忘初心：像初学者一样拥有一颗谦虚、开放的心态。
 * 李学峰
 */
public class ExceIUtils {
   static HSSFWorkbook workbook;
   static HSSFSheet sheet;
   public static void createFirst(String headname){
        workbook = new HSSFWorkbook();
       sheet = workbook.createSheet(headname);
       HSSFRow row = sheet.createRow(0);
       String[] heads={"帐号","姓名","所属部门","角色"};
       for (int i=0;i<heads.length;i++){
           HSSFCell cell = row.createCell(i);
           cell.setCellValue(heads[i]);
       }
   }
     public static void createOthers(List<Employee>list){
    for (int i=0;i<list.size();i++){
        HSSFRow row = sheet.createRow(i + 1);
        Employee employee = list.get(i);
        HSSFCell cella = row.createCell(0);
        cella.setCellValue(employee.getEmployeenum());

        HSSFCell cellb = row.createCell(1);
        cellb.setCellValue(employee.getUsername());

        HSSFCell cellc = row.createCell(2);
        cellc.setCellValue(employee.getDept().getDeptname());

        HSSFCell celld = row.createCell(3);
        celld.setCellValue(employee.getRole().getRname());
    }
     }
     public static void export(OutputStream outputStream) throws IOException {
       sheet.setGridsPrinted(true);
       workbook.write(outputStream);
     }


}































